/* $Id: LanguageEntry.java 137 2011-08-29 20:33:36Z altdotua@gmail.com $ */

package alt.djudge.frontend.server.datatypes;

import java.io.Serializable;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import alt.djudge.frontend.shared.dto.admin.AdminDTOEntry;
import alt.djudge.frontend.shared.dto.admin.LanguageEntryDTO;


@PersistenceCapable(detachable="true")
public class LanguageEntry extends AbstractEntry implements Serializable
{
	private static final long serialVersionUID = 1L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	protected Long id;
	
	@Override
	public Long getId()
	{
		return id;
	}
	
	@Override
	public void setId(Long id)
	{
		this.id = id;
	}
	
	@Persistent
	private String sid;
	
	@Persistent
	private String name;
	
	@Persistent
	private String djudgeId;
	
	public LanguageEntry()
	{
		// TODO Auto-generated constructor stub
	}
	
	public String getSid()
	{
		return sid;
	}

	public void setSid(String sid)
	{
		this.sid = sid;
	}

	public String getName()
	{
		return name;
	}

	public void setName(String name)
	{
		this.name = name;
	}

	public String getDjudgeId()
	{
		return djudgeId;
	}

	public void setDjudgeId(String djudgeId)
	{
		this.djudgeId = djudgeId;
	}
	
	@Override
	public String toString()
	{
		return sid + ": " + name;
	}

	public LanguageEntry(LanguageEntryDTO entryDTO)
	{
		fromDTO(entryDTO);
	}
	
	@Override
	public void fromDTO(AdminDTOEntry entryDTO)
	{
		setSid(entryDTO.getFieldValue(1));
		setName(entryDTO.getFieldValue(2));
		setDjudgeId(entryDTO.getFieldValue(3));
	}

	@Override
	public LanguageEntryDTO ownAdminDTO()
	{
		return new LanguageEntryDTO(new String[] {
				"" + getId(),
				getSid(),
				getName(),
				getDjudgeId()
		});
	}
}
